#include "inputhandler.h"
#include <Debug/DEBUG.hpp>

InputHandler &InputHandler::getInstance()
{
    static InputHandler instance;
    return instance;
}

void InputHandler::registerCallback(const std::string &command, std::function<void (QJsonObject&, QJsonObject&)> func)
{
    if (routerMap.count(command) != 0) {
        throw std::runtime_error("当前已经注册args: " + command + " ，请检查编码");
    }
    DEBUG_INFO("已成功添加函数： " + command);
    routerMap.emplace(command, func);
}

std::function<void (QJsonObject&, QJsonObject&)>InputHandler::operator[](const std::string &args)
{
    return routerMap[args];
}

std::function<void (QJsonObject&, QJsonObject&)>InputHandler::get(const std::string &args)
{
    return routerMap[args];
}
